import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:vehicle_management/pages/bottom_bar_page/my_task_page.dart';
import 'package:vehicle_management/pages/bottom_bar_page/my_page.dart';
import 'package:vehicle_management/public.dart';

// ignore: must_be_immutable
class Home extends StatefulWidget {
  final index;
  Home({Key key, this.index = 0}) : super(key: key);
  @override
  State<StatefulWidget> createState() =>
      _HomeState(this.index);
}

class _HomeState extends State<Home> {
  int _currentIndex;
  static String appKey;
  _HomeState(index) {
    this._currentIndex = index;
    // ignore: unnecessary_brace_in_string_interps
  }

  List _pageList = [
    TaskPage(), //任务界面
    MineScreen(), //我的界面
  ];
  @override
  Widget build(BuildContext context) {
    appKey = preferences.getString("appKey");

    return Scaffold(
      body: this._pageList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        iconSize: 36, //底部图标大小
        fixedColor: Colors.red,

        ///选中后的颜色
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.date_range),
            title: Text("任务"),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person),
            title: Text('我的'),
          ),
        ],
      ),
    );
  }

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}
